﻿using D20.Entities.Items;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using D20.Entities.Items.Weaponry;
using System;

namespace D20.UnitTests.Characters
{
    
    
    /// <summary>
    ///This is a test class for InventoryTest and is intended
    ///to contain all InventoryTest Unit Tests
    ///</summary>
    [TestClass()]
    public class InventoryTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Contents
        ///</summary>
        [TestMethod()]
        [DeploymentItem("D20.dll")]
        public void ContentsTest()
        {
            Inventory target = new Inventory();
            Item item = new Item();
            item.Identity.Name = "LOLWUT";
            target.AddItem(item);

            Assert.IsTrue(target.Contents.Contains(item));
        }

        /// <summary>
        ///A test for Capacity
        ///</summary>
        [TestMethod()]
        public void CapacityTest()
        {
            Inventory target = new Inventory();
            target.Capacity = 45;
            for (int i = 0; i < 45; i++)
            {
                target.AddItem(new Item());
            }
            bool thrown = false;
            try
            {
                target.AddItem(new Item());
            }
            catch (InvalidOperationException)
            {
                thrown = true;                
            }
            Assert.IsTrue(thrown);
        }

        /// <summary>
        ///A test for AddItem
        ///</summary>
        [TestMethod()]
        public void AddItemTest()
        {
            Inventory target = new Inventory(); 
            Item item = new MeleeWeapon();
            item.MaxHealth = 340;
            item.Health = 124;
            target.AddItem(item);
            Assert.IsTrue(target.Contents.Contains(item), "Target doesn't contain item.");
        }

        /// <summary>
        ///A test for Inventory Constructor
        ///</summary>
        [TestMethod()]
        public void InventoryConstructorTest1()
        {
            Inventory target = new Inventory();
            Assert.IsNotNull(target.Contents);
        }

        /// <summary>
        ///A test for Inventory Constructor
        ///</summary>
        [TestMethod()]
        public void InventoryConstructorTest()
        {
            Item i = new Item() { MaxHealth=124, Health = 123 };
            IEnumerable<Item> contents = new List<Item>() { i };
            Inventory target = new Inventory(contents);
            Assert.IsTrue(target.Contents.Contains(i));
        }
    }
}
